package org.zjx.core;

import lombok.Data;
import org.zjx.task.core.ITaskChain;
import org.zjx.task.core.TaskScheduler;
import org.zjx.task.repository.TaskChainGenerator;
import org.zjx.task.repository.TaskChainRepository;
import org.zjx.task.repository.TaskRepository;

import java.util.List;

@Data
public class TaskManager {
    private final TaskRepository taskRepository;
    private final TaskChainRepository chainRepository;
    private final TaskChainGenerator chainGenerator;
    private final TaskScheduler scheduler;

    public TaskManager(GameInstance gameInstance) {
        taskRepository = new TaskRepository("org.zjx.task.tasks");
        chainRepository = new TaskChainRepository("org.zjx.task.chains");
        chainGenerator = new TaskChainGenerator(taskRepository, chainRepository);
        scheduler = new TaskScheduler(4,gameInstance);

    }

    public List<ITaskChain> getChains(String str){
        return chainGenerator.generateChainsFromConfigFile(str);
    }

    public void add(ITaskChain chain){
        scheduler.addChain(chain);
    }

    public void add(List<ITaskChain> chains){
        scheduler.addChainToHead(chains);
    }

    public void shutdown(){
        scheduler.shutdown();
        scheduler.interrupt();
    }
}
